﻿using Sovacode.RubiksCube.Common.Managers.Settings;

namespace Sovacode.DemoApp
{
    /// <summary>
    /// Simple implementation for Configuration Manager. That's all what you need to use local config file
    /// </summary>
    public sealed class LocalSettings /*
                                       * To use local config file you need only expose SettingsManager class and
                                       * override 3 methods. See below.
                                       * After you need to add it to view model. See MainWindow.xaml.cs
                                       */
        : SettingsManager
    {
        /// <summary>
        /// Puts the setting.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="settingName">Name of the setting.</param>
        /// <param name="setting">The setting.</param>
        public override void PutSetting<T>(string settingName, T setting)
        {
            /* Put new value to cache of config file */
            Properties.Settings.Default[settingName] = setting;
        }

        /// <summary>
        /// Casts to.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="settingName">Name of the setting.</param>
        /// <returns>``0.</returns>
        protected override T CastTo<T>(string settingName)
        {
            /* Get from local cache of config file value of setting */
            return (T)Properties.Settings.Default[settingName];
        }

        /// <summary>
        /// Save settings
        /// </summary>
        public override void SaveSettings()
        {
            /* Saves config file */
            Properties.Settings.Default.Save();
        }
    }
}